package cn.cqk.v6.handle;

import cn.cqk.v6.builder.SopProcessBuilder;
import cn.cqk.v6.enums.Event;
import cn.cqk.v6.enums.State;
import cn.cqk.v6.iface.IStateHandle;
import cn.cqk.v6.iface.impl.*;

import java.util.Arrays;
import java.util.List;

class NewStateMachine extends AbstractStateMachine {


    @Override
    List<SopProcess> init() {
        return Arrays.asList(
                SopProcessBuilder.getInstance()
                        .from(State.UN_SUBMIT)
                        .event(Event.SUBMIT)
                        .handle(new EmpSubmitHandle())
                        .to(State.LEADER_CHECK)
                        .build(),
                SopProcessBuilder.getInstance()
                        .from(State.LEADER_CHECK)
                        .event(Event.PASS)
                        .handle(new LeaderPassHandle())
                        .to(State.HR_CHECK)
                        .build(),
                SopProcessBuilder.getInstance()
                        .from(State.LEADER_CHECK)
                        .event(Event.REJECT)
                        .handle(new LeaderRejectHandle())
                        .to(State.REJECT)
                        .build(),
                SopProcessBuilder.getInstance()
                        .from(State.HR_CHECK)
                        .event(Event.PASS)
                        .handle(new HRPassHandle())
                        .to(State.FINISH)
                        .build(),
                SopProcessBuilder.getInstance()
                        .from(State.HR_CHECK)
                        .event(Event.REJECT)
                        .handle(new HRRejectHandle())
                        .to(State.REJECT)
                        .build()
        );
    }

    public static void main(String[] args) {
        NewStateMachine newStateMachine = new NewStateMachine();
        IStateHandle<String, String> stateHandle = newStateMachine.getHandle(State.LEADER_CHECK, Event.REJECT);
        String result = stateHandle.handle("员工提离职");
        System.out.println(result);
        State state = newStateMachine.getNextState(State.LEADER_CHECK, Event.REJECT);
        System.out.println("当前状态为："+state);
    }
}
